package com.czxy.dao;

import com.czxy.domain.Order;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface OrderMapper extends Mapper<Order> {


    // 根据用户id 查询 所有的订单
    @Select("select * from orders where uid = #{uid} order by ordertime desc")
    @Results(id = "orderAllInfo",value = {
            @Result(property = "oid",column = "oid"),
            @Result(property = "itemList",
            many = @Many(select = "com.czxy.dao.OrderItemMapper.findOrderItemsByOid"),
            column = "oid")
    })
    public List<Order> findOrdersByUid(@Param("uid") String uid);


    @Select(" select * from orders where oid = #{oid} ")
//    @Results({
//            @Result(property = "oid",column = "oid"),
//            @Result(property = "itemList",
//            many = @Many(select = "com.czxy.dao.OrderItemMapper.findOrderItemsByOid"),
//            column = "oid")
//    })
    @ResultMap("orderAllInfo")
    public Order findOrderByOid(@Param("oid") String oid);



    // 更新收货人信息到指定的订单
    @Update("update orders set address=#{address},name=#{name},telephone=#{telephone} where oid = #{oid}")
    public void updateOrder(Order order);

    // 更新指定订单的支付状态
    @Update("update orders set state = #{state} where oid = #{oid} ")
    public void updateOrderState(@Param("oid") String oid, @Param("state") Integer state);



}
